﻿using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Const;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Base
{
    public partial class Base_BaseData_Setting_List : BaseForm
    {
        ServiceComm service = new ServiceComm();
        public Base_BaseData_Setting_List()
        {
            InitializeComponent();
            for (int i = DateTime.Now.Year - 1; i <= DateTime.Now.Year + 2; i++)
            {
                this.comboBoxEdit1.Properties.Items.Add(i.ToString());
            }
            BindModel();
        }

        private void BindModel()
        {
            using (DataTable dt = service.GetSystemInfoDataTable(ConstSystem.SystemYear + "," + ConstSystem.SystemSchoolNo + "," + ConstSystem.SystemSchoolName))
            {
                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow[] drs = dt.Select("SystemInfoID='" + ConstSystem.SystemYear + "'");
                    if (drs.Length > 0)
                    {
                        comboBoxEdit1.Text = drs[0]["SystemInfoName"].ToString();
                    }
                    drs = dt.Select("SystemInfoID='" + ConstSystem.SystemSchoolNo + "'");
                    if (drs.Length > 0)
                    {
                        txtSchoolNO.Text = drs[0]["SystemInfoName"].ToString();
                    }
                    drs = dt.Select("SystemInfoID='" + ConstSystem.SystemSchoolName + "'");
                    if (drs.Length > 0)
                    {
                        txtSchoolName.Text = drs[0]["SystemInfoName"].ToString();
                    }
                }
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (this.comboBoxEdit1.Text.Length == 0)
            {
                DevHelper.ShowInfoMessageBox("请先选择年度!");
                this.comboBoxEdit1.Focus();
                return;
            }
            if (this.txtSchoolNO.Text.Length == 0)
            {
                DevHelper.ShowInfoMessageBox("请先输入学校编码!");
                this.txtSchoolNO.Focus();
                return;
            }
            if (this.txtSchoolName.Text.Length == 0)
            {
                DevHelper.ShowInfoMessageBox("请先输入学校名称!");
                this.txtSchoolName.Focus();
                return;
            }
            List<TB_Sys_SystemInfo> list = new List<TB_Sys_SystemInfo>();
            list.Add(new TB_Sys_SystemInfo() { SystemInfoName = this.comboBoxEdit1.Text, SystemInfoID = ConstSystem.SystemYear, SystemInfoRemark = "考试年度Key" });
            list.Add(new TB_Sys_SystemInfo() { SystemInfoName = txtSchoolNO.Text, SystemInfoID = ConstSystem.SystemSchoolNo, SystemInfoRemark = "学校代码Key" });
            list.Add(new TB_Sys_SystemInfo() { SystemInfoName = txtSchoolName.Text, SystemInfoID = ConstSystem.SystemSchoolName, SystemInfoRemark = "学校名称Key" });
            if (service.SaveSystemInfo(list))
            {
                SessionerHelper.SystemYear = this.comboBoxEdit1.Text;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
